/*
*	Ivan Concua 12352
*	Roberto Andrino 12413
*	Algoritmos y estructuras de datos
*	SinglyLinkedList.java
*	Implementacion de List. SinglyLinkedList es una lista
*	simplemente encadenada. Es parte del ADT de List
*/

public class SinglyLinkedList<E> extends AbstractList<E>
{

   protected int count; // list size
   protected Node<E> head; // ref. to first element

   public SinglyLinkedList()
   // post: generates an empty list
   {
      head = null;
      count = 0;
   }
   
   public int size()
   // post: returns number of elements in list
  {
      return count;
  }
  
  public void push(E value)
  // post: value is added to beginning of list
  {
	  // note order that things happen:
	  // head is parameter, then assigned
	  head = new Node<E>(value, head);
	  count++;
  }
  
  public E pop()
  // pre: list is not empty
  // post: removes and returns value from beginning of list
 {
     Node<E> temp = head;
     head = head.next(); // move head down list
     count--;
     return temp.value();
  }
  
  public E peek()
  // pre: list is not empty
  // post: returns first value in list
  {
      return head.value();
  }
}